﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JieBooLaw.WebSite
{
    using JieBooLaw.Service;
    using JieBooLaw.Domain;
    using JieBooLaw.Common.Web.Util;
    using System.Text;
    using System.Data;
    public partial class MainMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!this.IsPostBack)
            {
               this.TbId.InnerHtml = MenuBar();
            }
        }
        public string MenuBar()
        {

            TInfoRelease_ItemSvc ItmSvc = new TInfoRelease_ItemSvc();
            IList<TInfoRelease_Item> ItmEntiy = ItmSvc.GetAllList();
            IList<TInfoRelease_Item> FileItmEntiy = (from ListItm in ItmEntiy where ListItm.PItemID.Equals(13) select ListItm).ToList<TInfoRelease_Item>();
            StringBuilder SubStr = new StringBuilder();
            SubStr.Append("<ul>");
            foreach (TInfoRelease_Item ltm in FileItmEntiy)
            {
                SubStr.Append(" <li>");
                SubStr.Append("  <a href='" + ltm.LinkURL + "&itmid=" + ltm.ItemID + "'>" + ltm.ItemName + "</a> ");
                string strList = getSecod(ltm.ItemID, ItmEntiy);
                if (strList!=string.Empty)
                {
                    SubStr.Append("    <span style='display: none;'>");
                    SubStr.Append(strList);
                    SubStr.Append("    </span>");
                }
                SubStr.Append("   </li>  ");
            }
            return SubStr.ToString();

        }
        public string getSecod(int? ItmId, IList<TInfoRelease_Item> Ls)
        {
            StringBuilder Txt = new StringBuilder();
            IList<TInfoRelease_Item> Litm = (from ListItm in Ls where ListItm.PItemID.Equals(ItmId) select ListItm).ToList<TInfoRelease_Item>();
            foreach (TInfoRelease_Item Sitm in Litm)
            {
                Txt.Append("<a href='" + Sitm.LinkURL + "?id=" + Sitm.ItemID.ToString() + "&itmid=" + Sitm.PItemID+ "'>" + Sitm.ItemName + "</a>");
            }
            return Txt.ToString();
        }
    }
}
